def prime(num):
    for i in range(2,num):
        if num % i == 0:
            return False
        return True

    def max_prime(num):
        if num <= 999 or num > 9999:
            return 0

        a = num // 1000
        b = (num % 1000) // 100
        c = (num % 100) // 10
        d = num % 10
        mmax_ ch = 0
        for ch in (num, a,b,c,d, a*10 +b, b*10 +c, c*10 +d, a*100 +b*10+c,b*100+c*10+d) :
            if prime (ch) and ch>max_ch:
                max_ch= ch
                return max_ch

            num = int(input("Введите четырехзначное число:"))
            result = max_prime(num)
            print(result)
